﻿<?xml version="1.0" encoding="utf-8" ?>
<!-- 
/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Shared Source License
* for DSL Editor PowerToy. A copy of the license can be found in the License.htm file
* at the root of this distribution. If you can not locate the Shared Source License
* for DSL Editor PowerToy, please obtain a copy from: http://www.codeplex.com/dsltreegrideditor/Project/License.aspx.
* By using this source code in any fashion, you are agreeing to be bound by
* the terms of the Shared Source License for DSL Editor PowerToy.
*
* You must not remove this notice, or any other, from this software.
*
* **********************************************************************************/
-->
<Recipe Name="AddToDSLSolution" Recurrent="true" Bound="false" xmlns="http://schemas.microsoft.com/pag/gax-core" xmlns:xi="http://www.w3.org/2001/XInclude">
  <DocumentationLinks>
    <Link Caption="How to use this PowerToy?" Url="http://www.codeplex.com/dsltreegrideditor/Wiki/View.aspx?title=ReleaseM1_Use" Kind="Documentation"/>
    <Link Caption="What does this recipe do?" Url="http://www.codeplex.com/dsltreegrideditor/Wiki/View.aspx?title=ReleaseM1_Recipe_AddToDSLSolution" Kind="Documentation"/>
    <Link Caption="Re-install the Editors" Url="recipe://AddToDSLSolution" Kind="NextStep" />
    <Link Caption="Remove the Editors" Url="recipe://RemoveFromDSLSolution" Kind="NextStep" />
    <Link Caption="How to customize?" Url="http://www.codeplex.com/dsltreegrideditor/Wiki/View.aspx?title=ReleaseM1_Customize" Kind="NextStep"/>
  </DocumentationLinks>
  <xi:include href="Common/CommonTypeAliases.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
  <Caption>Add DSL Editors</Caption>
  <HostData>
    <Icon ID="213" />
    <CommandBar Name="Solution" />
  </HostData>
  <Arguments>
    <Argument Name="DslPackageProject" Type="EnvDTEProject" Required="true"/>
    <Argument Name="FullDestFolderPath" Type="System.String" Required="true">
      <Converter Type="RelativeFolderPathConverter"/>
      <ValueProvider Type="ExpressionEvaluatorValueProvider"
         Expression="DslEditors">
      </ValueProvider>
    </Argument>
    <Argument Name="AbsDestFolderPath" Type="System.String" Required="true">
      <ValueProvider Stage="OnBeginActions" Type="PhysicalProjectFolderPathValueProvider"
         ProjectArgument="DslPackageProject" FolderArgument="FullDestFolderPath">
        <MonitorArgument Name="FullDestFolderPath" />
        <MonitorArgument Name="DslPackageProject" />
      </ValueProvider>
    </Argument>
    <xi:include href="Common/Arguments/Paths.xml" xpointer="xmlns(gax=http://schemas.microsoft.com/pag/gax-core) xpointer(/gax:Arguments/gax:Argument)" />
    <Argument Name="GeneratedCodeFolderDepth" Type="System.Int32">
      <ValueProvider Type="FolderPathDepthValueProvider"
         FolderPath="$(FullDestFolderPath)\GeneratedCode">
        <MonitorArgument Name="FullDestFolderPath" />
      </ValueProvider>
    </Argument>
    <Argument Name="CtcFilePath" Type="System.String" Required="true">
      <Converter Type="ProjectItemExistsConverter" ItemType="File" ProjectArgument="DslPackageProject"/>
      <ValueProvider Type="ProjectItemValueProvider" 
        ProjectArgument="DslPackageProject" ItemType="File" DefaultValue="CtcComponents\Commands.ctc">
        <MonitorArgument Name="DslPackageProject" />
      </ValueProvider>
    </Argument>
    <Argument Name="DslPackageProjectDefaultNamespace" Type="System.String" Required="true">
      <ValueProvider Type="ProjectPropertyValueProvider"
          ProjectArgument="DslPackageProject" Property="DefaultNamespace">
        <MonitorArgument Name="DslPackageProject" />
      </ValueProvider>
    </Argument>
  </Arguments>
  <GatheringServiceData>
    <Wizard xmlns="http://schemas.microsoft.com/pag/gax-wizards" SchemaVersion="1.0">
      <Pages>
        <Page Height="300">
          <Title>Basic Configuration</Title>
          <Fields>
            <Field ValueName="DslPackageProject" Label="Dsl Package Project">
              <Help>Select the 'DslPackage' project of your DSL</Help>
              <Editor Type="Microsoft.Practices.RecipeFramework.Library.Editors.SolutionPickerEditor, Microsoft.Practices.RecipeFramework.Library" />
            </Field>
          </Fields>
        </Page>
        <Page Height="300">
          <Title>Advanced Configuration</Title>
          <Fields>
            <Field ValueName="FullDestFolderPath" Label="New Folder">
              <Help>Folder where all files will be put.  Note, all previously added files in this folder will be overwritten.</Help>
            </Field>
            <Field ValueName="CtcFilePath" Label="Full Path to .ctc File">
              <Help>Enter the path to the project CTC file (containing the menu and command definitions)</Help>
            </Field>
          </Fields>
        </Page>
      </Pages>
    </Wizard>
  </GatheringServiceData>
  <Actions>
    <Action Name="Trace0" Type="WriteTraceAction" Pane="Package" Message="Starting configuration on: '$(DslPackageProject.Name)'"/>

    <!-- Cleanup -->
    <xi:include href="Common/Actions/Cleanup.xml" xpointer="xmlns(gax=http://schemas.microsoft.com/pag/gax-core) xpointer(/gax:Actions/gax:Action)" />

    <!-- Add Project Dependency References (From GAC) -->
    <Action Name="Trace1" Type="WriteTraceAction" Pane="Package" Message="Adding assembly references"/>
    <Action Name="AddAssemblyReferences" Type="AddAssembliesReferenceAction"
            FileNames="System.Data;DslEditorPowerToy.Languages.Common;DslEditorPowerToy.Controls.Common;DslEditorPowerToy.Controls.Languages;DslEditorPowerToy.Controls.Editors">
      <Input Name="ReferringProject" RecipeArgument="DslPackageProject" />
    </Action>

    <!-- Create Destination Folders (if not exist) -->
    <Action Name="Trace21" Type="WriteTraceAction" Pane="Package" Message="Creating destination folder for powertoy files: '$(FullDestFolderPath)'"/>
    <Action Name="EnsureDestFolderPath" Type="AddProjectFolderAction">
      <Input Name="FolderPath" RecipeArgument="FullDestFolderPath" />
      <Input Name="ReferringProject" RecipeArgument="DslPackageProject" />
      <Output Name="NewFolder"/>
    </Action>
    <Action Name="Trace22" Type="WriteTraceAction" Pane="Package" Message="Creating destination folder for generated files: '$(GeneratedCodeFolderPath)'"/>
    <Action Name="EnsureGeneratedCodeFolderPath" Type="AddProjectFolderAction">
      <Input Name="FolderPath" RecipeArgument="GeneratedCodeFolderPath" />
      <Input Name="ReferringProject" RecipeArgument="DslPackageProject" />
      <Output Name="NewFolder"/>
    </Action>
    <Action Name="Trace23" Type="WriteTraceAction" Pane="Package" Message="Creating destination folder for resource files: '$(ResourcesFolderPath)'"/>
    <Action Name="EnsureResourcesFolderPath" Type="AddProjectFolderAction">
      <Input Name="FolderPath" RecipeArgument="ResourcesFolderPath" />
      <Input Name="ReferringProject" RecipeArgument="DslPackageProject" />
      <Output Name="NewFolder"/>
    </Action>

    <!-- Generate Text Template artefacts -->
    <Action Name="Trace31" Type="WriteTraceAction" Pane="Package" Message="Generating new text templates"/>
    <Action Name="GenerateDslEditorsDefinitionTT" Type="TextTemplateAction"
      Template="Text\DslEditorsDefinition.deptec.tt">
      <Input Name="AbsDestFolderPath" RecipeArgument="AbsDestFolderPath" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateCommandIdTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\CommandId.cs.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateCommandSetTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\CommandSet.cs.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateConstantsTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\Constants.cs.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateCustomCmdTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\CustomCmd.h.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateDesignerTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\Designer.cs.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateDocViewTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\DocView.cs.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateDslEditorsResxTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\DslEditorsResx.resx.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateEditorsTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\Editors.cs.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Input Name="DestFolderName" RecipeArgument="FullDestFolderPath" />
      <Output Name="Content" />
    </Action>
    <Action Name="GeneratePackageTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\Package.cs.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateToolWindowTT" Type="TextTemplateAction"
      Template="Text\GeneratedCode\ToolWindow.cs.tt.tt">
      <Input Name="GeneratedCodeFolderDepth" RecipeArgument="GeneratedCodeFolderDepth" />
      <Input Name="DestFolderName" RecipeArgument="FullDestFolderPath" />
      <Output Name="Content" />
    </Action>
    
    <!-- Add Artefacts to Destination Folders -->
    <Action Name="Trace41" Type="WriteTraceAction" Pane="Package" Message="Adding generated files to folder: '$(FullDestFolderPath)'"/>
    <Action Name="AddDslEditorsDefinitionTT" Type="AddItemFromStringToProjectItemAction"
        Open="true" TargetFileName="DslEditorsDefinition.deptec">
      <Input Name="Content" ActionOutput="GenerateDslEditorsDefinitionTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureDestFolderPath.NewFolder" />
    </Action>
    <Action Name="Trace42" Type="WriteTraceAction" Pane="Package" Message="Adding generated files to folder: '$(ResourcesFolderPath)'"/>
    <Action Name="AddDslEditorsToolWindowsBMP" Type="AddItemFromTemplateToProjectItemAction"
        Template="Text\Resources\DslEditorsToolWindowBitmaps.bmp">
      <Input Name="InputProjectItem" ActionOutput="EnsureResourcesFolderPath.NewFolder" />
    </Action>
    <Action Name="AddExampleEditor1BMP" Type="AddItemFromTemplateToProjectItemAction"
        Template="Text\Resources\ExampleEditorBitmap1.bmp">
      <Input Name="InputProjectItem" ActionOutput="EnsureResourcesFolderPath.NewFolder" />
    </Action>
    <Action Name="AddExampleEditor2BMP" Type="AddItemFromTemplateToProjectItemAction"
        Template="Text\Resources\ExampleEditorBitmap2.bmp">
      <Input Name="InputProjectItem" ActionOutput="EnsureResourcesFolderPath.NewFolder" />
    </Action>
    <Action Name="AddExampleEditor3BMP" Type="AddItemFromTemplateToProjectItemAction"
        Template="Text\Resources\ExampleEditorBitmap3.bmp">
      <Input Name="InputProjectItem" ActionOutput="EnsureResourcesFolderPath.NewFolder" />
    </Action>
    <Action Name="Trace43" Type="WriteTraceAction" Pane="Package" Message="Adding generated files to folder: '$(GeneratedCodeFolderPath)'"/>
    <Action Name="AddCommandIdTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="CommandId.tt">
      <Input Name="Content" ActionOutput="GenerateCommandIdTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddCommandSetTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="CommandSet.tt">
      <Input Name="Content" ActionOutput="GenerateCommandSetTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddConstantsTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="Constants.tt">
      <Input Name="Content" ActionOutput="GenerateConstantsTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddCustomCmdTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="CustomCmd.tt">
      <Input Name="Content" ActionOutput="GenerateCustomCmdTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddDesignerTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="Designer.tt">
      <Input Name="Content" ActionOutput="GenerateDesignerTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddDocViewTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="DocView.tt">
      <Input Name="Content" ActionOutput="GenerateDocViewTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddDslEditorsResxTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="DslEditorsResx.tt">
      <Input Name="Content" ActionOutput="GenerateDslEditorsResxTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddEditorsTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="Editors.tt">
      <Input Name="Content" ActionOutput="GenerateEditorsTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddPackageTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="Package.tt">
      <Input Name="Content" ActionOutput="GeneratePackageTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>
    <Action Name="AddToolWindowTT" Type="AddItemFromStringToProjectItemAction"
        Open="false" TargetFileName="ToolWindow.tt">
      <Input Name="Content" ActionOutput="GenerateToolWindowTT.Content" />
      <Input Name="InputProjectItem" ActionOutput="EnsureGeneratedCodeFolderPath.NewFolder" />
    </Action>

    <!--Add INCLUDE and MACROS Commands.ctc file -->
    <Action Name="Trace61" Type="WriteTraceAction" Pane="Package" Message="Adding #include statement to CTC file"/>
    <Action Name="AppendHeaderInclude" Type="AppendLineToTextFileAction"
        SearchExpression="\#include" AppendText="#include &quot;..\$(GeneratedCodeFolderPath)\CustomCmd.h&quot;" 
        Position="After" Occurance="Last">
      <Input Name="TargetFilePath" RecipeArgument="CtcFilePath" />
      <Input Name="Project" RecipeArgument="DslPackageProject" />
    </Action>
    <Action Name="Trace62" Type="WriteTraceAction" Pane="Package" Message="Adding macros declarations to CTC file"/>
    <Action Name="AppendGroupMacro" Type="AppendLineToTextFileAction"
        SearchExpression="NEWGROUPS_END" AppendText="&#9;&#9;DSLEDITORPOWERTOY_GROUPS" 
        Position="Before" Occurance="First">
      <Input Name="TargetFilePath" RecipeArgument="CtcFilePath" />
      <Input Name="Project" RecipeArgument="DslPackageProject" />
    </Action>
    <Action Name="AppendButtonMacro" Type="AppendLineToTextFileAction"
        SearchExpression="BUTTONS_END" AppendText="&#9;&#9;DSLEDITORPOWERTOY_BUTTONS" 
        Position="Before" Occurance="First">
      <Input Name="TargetFilePath" RecipeArgument="CtcFilePath" />
      <Input Name="Project" RecipeArgument="DslPackageProject" />
    </Action>
    <Action Name="AppendCommandPlacementMacro" Type="AppendLineToTextFileAction"
        SearchExpression="CMDPLACEMENT_END" AppendText="&#9;DSLEDITORPOWERTOY_CMDPLACEMENT" 
        Position="Before" Occurance="First">
      <Input Name="TargetFilePath" RecipeArgument="CtcFilePath" />
      <Input Name="Project" RecipeArgument="DslPackageProject" />
    </Action>

    <!-- Save Configuration Info -->
    <Action Name="Trace71" Type="WriteTraceAction" Pane="Package" Message="Marking project as configured"/>
    <Action Name="MarkAsPowerToyProject" Type="AddProjectGlobalsEntryAction"
        PropertyName="DSLPowerEditorToyEditor" PropertyValue="Configured">
      <Input Name="Project" RecipeArgument="DslPackageProject" />
    </Action>
    <Action Name="Trace72" Type="WriteTraceAction" Pane="Package" Message="Saving recipe configuration"/>
    <Action Name="SaveDestFolderPath" Type="AddProjectGlobalsEntryAction"
        PropertyName="DSLPowerEditorToyEditor_AddedFolder">
      <Input Name="PropertyValue" RecipeArgument="FullDestFolderPath" />
      <Input Name="Project" RecipeArgument="DslPackageProject" />
    </Action>
    <Action Name="SaveCtcFileLocation" Type="AddProjectGlobalsEntryAction"
        PropertyName="DSLPowerEditorToyEditor_CtcFile">
      <Input Name="PropertyValue" RecipeArgument="CtcFilePath" />
      <Input Name="Project" RecipeArgument="DslPackageProject" />
    </Action>
    
    <Action Name="Trace8" Type="WriteTraceAction" Pane="Package" Message="Configuration complete."/>
  </Actions>
</Recipe>
